<?php
//to get the government mla users
  $path = drupal_get_path('module', 'government');
  drupal_add_css($path . '/css/government.css');

function governement_mlausers() {


$mlatitle  = t('MLA Profiles');
$title2=t('MLA Profiles');
global $language;
//print_r($language);
 my_db_change(1);
if($language->language=='ta')
	$lang = 'ta';
else
	$lang = 'en';



drupal_set_title($mlatitle);

$table = array(
'#theme' => 'table',
'#header' => array(t('Constituency No'),t('Constituency Name'),t('Name'), t('Party'), t('District')),
'#rows'=> array(),
);

$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', 'mlaprofile')
  ->propertyCondition('status',1)
  ->propertyCondition('language', $language->language, '=')
   ->fieldCondition('field_mla_assembly','value',14,'=')
   ->fieldOrderBy('field_mla_cons', 'value','ASC')
     ->pager(25,0);
$result = $query->execute();
//print_r($result); die;
if (isset($result['node'])) {
  $news_items_nids = array_keys($result['node']);

  $news_items = entity_load('node', $news_items_nids);
}
 my_db_change(0);
 foreach ($news_items as $row) {
 $mla_id = $row->tnid;
 $cons_no_pad = str_pad($row->field_mla_cons['und'][0]['value'], 3, "0", STR_PAD_LEFT);
$cons_no=t($cons_no_pad);
$constituencey_name = t(consituance_name($row->field_mla_cons['und'][0]['value']));
$title=$row->title;
$paryt_name=t(paty_name($row->field_mla_party['und'][0]['value']));
$cons_district=t(consticy_District_name($row->field_mla_district['und'][0]['value']));

//print "<pre>"; print_r($row); print "</pre>";
$table['#rows'][]=array($cons_no,$constituencey_name,l($title,'government/mlas/'.$mla_id),$paryt_name,$cons_district);
}



 $output	=	"<div style='text-align:right;'><a onclick='javascript:history.go(-1)' style='cursor:pointer;' alt='Go Back' title='Go Back'><font style='color:maroon;font-weight:bold;'> " .t('Back')."</font></a></div>";
//$pagers = "<div>".theme('pager')."</div>";

$pager['pager_pager'] = array(
        '#theme' => 'pager',
		);

return array($output,$table,$pager);


}


//to view the mla detail page
function governement_mla_data() {
global $language;

 my_db_change(1);
 $gid = arg(2);


$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', 'mlaprofile')
  ->propertyCondition('status',1)
  ->propertyCondition('language', $language->language, '=')
->propertyCondition('tnid', $gid);

$result = $query->execute();
//print "<pre>"; print_r($result); print "</pre>";



if (isset($result['node'])) {
  $news_items_nids = array_keys($result['node']);
  $nid = current($result['node'])->nid;
  $vid = $result['node'][$nid]->vid;

  //$news_items = entity_load('node', $news_items_nids);
  $news_items = entity_load('node', $news_items_nids, array('vid' => $vid));
}

//print "<pre>"; print_r($news_items); print "</pre>";die;
my_db_change(0);

 $output = theme('mla_user_profile_theme',array('results' => $news_items,'nid'=>$nid));
return $output;
}




//cm,cj,governor datas
function governement_keycontacts_data($gid) {
global $language;
 my_db_change(1);
 $gid = arg(2);

 if($language->language=='ta') {
	$gid = $gid;
	$Lanid = "tnid";
}else{
	$gid = $gid;
	$Lanid = "nid";

}
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', 'profile_form')
  ->propertyCondition('status',1)
  ->propertyCondition($Lanid,  $gid,'=')
  ->propertyCondition('language', $language->language, '=');

$result = $query->execute();

$nid = current($result['node'])->nid;

if (isset($result['node'])) {
  $news_items_nids = array_keys($result['node']);

  $news_items = entity_load('node', $news_items_nids);
}
//print_r($news_items);
 my_db_change(0);
 $output = theme('keycontacts_user_profile_theme',array('results' => $news_items,'nid'=>$nid));
return $output;

}
//Loksabha List datas
function governement_lokshabausers() {
global $language,$base_url;
//print_r($language);
 my_db_change(1);
 $gid = arg(2);

 if($language->language=='ta') {
    $gid = $gid;
    $Lanid = "tnid";
}else{
    $gid = $gid;
    $Lanid = "nid";
}

$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', 'mpsprofile')
   ->propertyCondition('status',1)
   //->fieldOrderBy('field_mp_constituencey_name', 'value','ASC')
   ->fieldOrderBy('field_mp_constituencey_name', 'value','ASC')
 ->pager(12,0) ;

$result = $query->execute();

$nid = current($result['node'])->nid;

if (isset($result['node'])) {
  $news_items_nids = array_keys($result['node']);
  $news_items = entity_load('node', $news_items_nids);
}
// print_r($nid);
//print "<pre>"; print_r($news_items);
my_db_change(0);

     $table = array(
          '#theme' => 'table',
          '#header' => array(t('Constituency No'),t('Constituency Name'),t('Name'), t('Party')),
          '#rows'=> array(),
        );

        foreach ($news_items as $row) {
        //print $base_url;
         //$uid=$row->nid;
         $constituencey_no=$row->field_mp_constituencey_name['und'][0]['value'];
         $constituencey=lok_consituancency_name($row->field_mp_constituencey_name['und'][0]['value']);
         $title=$row->title;
         $party_name=paty_name($row->field__mp_party['und'][0]['value']);
         $photo=$row->field_mp_photo['und'][0]['uri'];

       $wrapper = file_stream_wrapper_get_instance_by_uri($photo);
       if($wrapper == true){
       $path = $wrapper->getDirectoryPath() . "/" . file_uri_target($photo);
       }

        $img = '<img  src= "http://cms.tn.gov.in//'.$path.'"  height="100">';

         //$name='<a href="'.$base_url.'/government/lokmember/'.$row->v=vid.'">'.$row->title.'</a>';

         $name = l($row->title,'/government/lokmember/'.$row->nid);
         $profileimg=$img.'<br/>'.$name;

        // print "<pre>"; print_r($row); print "</pre>";

        $table['#rows'][]=array($constituencey_no,$constituencey,$profileimg,$party_name);
        }

/*$output = theme('mp_profile_theme',array('results' => $news_items));
return $output;*/

$output    =    "<div style='text-align:right;'><a onclick='javascript:history.go(-1)' style='cursor:pointer;' alt='Go Back' title='Go Back'><font style='color:maroon;font-weight:bold;'> " .t('Back')."</font></a></div>";

$pager['pager_pager'] = array(
         '#theme' => 'pager',

  );

//return array($output,$table);
return array($output,$table,$pager);
//return $pager;
}


//lokshaba member data
function governement_lokmember_data($gid) {
global $language,$base_url;
// print $lannguage;
 my_db_change(1);
 $gid = arg(2);

 if($language->language=='ta') {
    $gid = $gid;
    $Lanid = "tnid";
}else{
    $gid = $gid;
    $Lanid = "nid";

}
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', 'mpsprofile')
   ->propertyCondition('status',1)
   ->propertyCondition('nid',$gid,'=');
   //->fieldOrderBy('field_mp_constituencey_name','value', 'ASC');
  // ->fieldOrderBy('field_mp_constituencey_name', 'value','ASC');

$result = $query->execute();

$nid = current($result['node'])->nid;

if (isset($result['node'])) {
  $news_items_nids = array_keys($result['node']);
  $news_items = entity_load('node', $news_items_nids);
}

$table = array(
          '#theme' => 'table',
          '#header' => array(t('Constituency No'),t('Constituency Name'),t('Name'), t('Party')),
          '#rows'=> array(),
        );

        foreach ($news_items as $row) {
        //print $base_url;
         //$uid=$row->nid;
         $constituencey_no=$row->field_mp_constituencey_name['und'][0]['value'];
         $constituencey=lok_consituancency_name($row->field_mp_constituencey_name['und'][0]['value']);
         //$constituencey_name=$row->field_mp_constituencey_name['und'][0]['value'];

         $title=$row->title;
         $constituencey_name=$row->field__mp_party['und'][0]['value'];
         $photo=$row->field_mp_photo['und'][0]['uri'];

       $wrapper = file_stream_wrapper_get_instance_by_uri($photo);
       if($wrapper == true){
       $path = $wrapper->getDirectoryPath() . "/" . file_uri_target($photo);
       }

         $img = '<img  src= "http://cms.tn.gov.in//'.$path.'"  height="100" >';

         //$name='<a href="'.$base_url.'/government/lokmember/'.$row->nid.'">'.$row->title.'</a>';
         $name = l($row->title,'/government/lokmember/'.$row->nid);
         $profileimg=$img.'<br/>'.$name;

        // print "<pre>"; print_r($row); print "</pre>";

        //$table['#rows'][]=array($row->field_mp_constituencey_name['und'][0]['value'],$row->field_mp_constituencey_name['und'][0]['value'],$profileimg,$row->field__mp_party['und'][0]['value']);

        }

//print "<pre>"; print_r($news_items);
my_db_change(0);
$output = theme('mp_profile_theme',array('results' => $news_items,'nid'=>$nid));
return $output;
}

//rajyasaba List datas
function governement_rajyasabausers() {
global $language,$base_url;
//print_r($language);
 my_db_change(1);
 $gid = arg(2);

$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', 'rajyasabha')
   ->propertyCondition('status',1)
 ->fieldOrderBy('field_mp_partyname', 'value','ASC');// ->pager(30,0) ;

$result = $query->execute();

$nid = current($result['node'])->nid;

if (isset($result['node'])) {
  $news_items_nids = array_keys($result['node']);
  $news_items = entity_load('node', $news_items_nids);
}
// print_r($nid);
//print "<pre>"; print_r($news_items);
my_db_change(0);

     $table = array(
          '#theme' => 'table',
          '#header' => array(t('S.No'),t('Name'),t('Member'), t('Party')),
          '#rows'=> array(),
        );

		$i=1;
        foreach ($news_items as $row) {

        //print $base_url;
         //$uid=$row->nid;

		 //$constituencey_no=$row->field_mp_constituencey_name['und'][0]['value'];
         //$constituencey=lok_consituancency_name($row->field_mp_constituencey_name['und'][0]['value']);
         $title=$row->title;
         $party_name=paty_name($row->field_mp_partyname['und'][0]['value']);
         $photo=$row->field_mp_image['und'][0]['uri'];
         $j=$i++;
       $wrapper = file_stream_wrapper_get_instance_by_uri($photo);
       if($wrapper == true){
       $path = $wrapper->getDirectoryPath() . "/" . file_uri_target($photo);
       }

        $img = '<img  src= "http://cms.tn.gov.in//'.$path.'"  height="100">';

         //$name='<a href="'.$base_url.'/government/lokmember/'.$row->v=vid.'">'.$row->title.'</a>';

         $name = l($row->title,'/government/rajyasaba/'.$row->nid);
         $profileimg=$img;

        // print "<pre>"; print_r($row); print "</pre>";

        $table['#rows'][]=array($j,$name,$profileimg,$party_name);
        }

/*$output = theme('mp_profile_theme',array('results' => $news_items));
return $output;*/

$output    =    "<div style='text-align:right;'><a onclick='javascript:history.go(-1)' style='cursor:pointer;' alt='Go Back' title='Go Back'><font style='color:maroon;font-weight:bold;'> " .t('Back')."</font></a></div>";

$pager['pager_pager'] = array(
         '#theme' => 'pager',

  );

//return array($output,$table);
return array($output,$table,$pager);
//return $pager;
}

/*Rajyasabha Members Data*/
function governement_rajyasaba_data() {
global $language,$base_url;
//print_r($language);
 my_db_change(1);
 $gid = arg(2);

$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', 'rajyasabha')
   ->propertyCondition('status',1)
   ->propertyCondition('nid',$gid)
 ->fieldOrderBy('field_mp_partyname', 'value','ASC')
 ->pager(30,0) ;

$result = $query->execute();

$nid = current($result['node'])->nid;

if (isset($result['node'])) {
  $news_items_nids = array_keys($result['node']);
  $news_items = entity_load('node', $news_items_nids);
}
// print_r($nid);
//print "<pre>"; print_r($news_items);
my_db_change(0);

     $table = array(
          '#theme' => 'table',
          '#header' => array(t('S.No'),t('Name'),t('Member'), t('Party')),
          '#rows'=> array(),
        );

		$i=1;
        foreach ($news_items as $row) {

        //print $base_url;
         //$uid=$row->nid;
         $title=$row->title;
         $party_name=paty_name($row->field_mp_partyname['und'][0]['value']);
         $photo=$row->field_mp_image['und'][0]['uri'];
         $j=$i++;
		   $wrapper = file_stream_wrapper_get_instance_by_uri($photo);
		   if($wrapper == true){
		   $path = $wrapper->getDirectoryPath() . "/" . file_uri_target($photo);
		   }

        $img = '<img  src= "http://cms.tn.gov.in//'.$path.'"  height="100">';

         //$name='<a href="'.$base_url.'/government/lokmember/'.$row->v=vid.'">'.$row->title.'</a>';

         $name = l($row->title,'/government/rajyasaba/'.$row->nid);
         $profileimg=$img;

        // print "<pre>"; print_r($row); print "</pre>";

        $table['#rows'][]=array($j,$name,$profileimg,$party_name);
        }

my_db_change(0);
$output = theme('mp_rajyasabha_profile_theme',array('results' => $news_items,'nid'=>$nid));
return $output;
}

?>